package xx.rabbitmq.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xx.rabbitmq.conf.ConfirmConfig;

import static xx.rabbitmq.conf.DeadConfig.EXCHANGE;
import static xx.rabbitmq.conf.DeadConfig.ROUTING_KEY;

@Slf4j
@RestController
@RequestMapping("/confirm")
public class DeadController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 5秒未被消费会路由到死信队列
     */
    @GetMapping("/publishExpir")
    public void publishExpir() {
        rabbitTemplate.convertAndSend(EXCHANGE, ROUTING_KEY, "hello expir dead", message -> {
            message.getMessageProperties().setExpiration("5000");
            return message;
        });
    }



}
